package org.seamon.management.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.seamon.management.mapper.RoleMapper;
import org.seamon.management.pojo.dto.RoleInsertDto;
import org.seamon.management.pojo.dto.RoleUpdateDto;
import org.seamon.management.pojo.entity.Role;
import org.seamon.management.service.RoleService;
import org.seamon.management.util.CacheConstants;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Simon
* @description 针对表【sys_role(角色表)】的数据库操作Service实现
* @createDate 2025-07-11 00:31:54
*/
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role>
    implements RoleService{

    @Override
    @Cacheable(cacheNames = {CacheConstants.ROLE_LIST})
    public List<Role> listRole() {
        return this.list();
    }

    @Override
    @CacheEvict(cacheNames = {CacheConstants.ROLE_LIST}, allEntries = true)
    public void save(RoleInsertDto dto) {
        Role role = new Role();
        BeanUtils.copyProperties(dto, role);
        this.save(role);
    }

    @Override
    @CacheEvict(cacheNames = {CacheConstants.ROLE_LIST}, allEntries = true)
    public void update(RoleUpdateDto dto) {
        Role role = new Role();
        BeanUtils.copyProperties(dto, role);
        this.updateById(role);
    }

    @Override
    @CacheEvict(cacheNames = {CacheConstants.ROLE_LIST}, allEntries = true)
    public void removeRoleById(Long id) {
        this.removeById(id);
    }
}




